<?php 
require_once 'database/Database.php';
require_once 'GlobalSettings.php';

class Utility
{	
	public static function assignClassProps(&$Obj,$ValueArray)
	{
		$reflect=new ReflectionClass($Obj);
		$props   = $reflect->getProperties(ReflectionProperty::IS_PUBLIC);		
		foreach ($props as $prop) 
		{
			if(isset($ValueArray[$prop->getName()]))
			{
				$prop->setValue($Obj,$ValueArray[$prop->getName()]);
			}		
		}
	}
	
	//delete all the empty elements in arrays
	public static function arrayRemoveEmpty(&$arr){
		if($arr==NULL)
			return false;
		foreach ($arr as $key => $value) 
		{
			if (is_array($value)) 
			{
				if(!self::arrayRemoveEmpty($arr[$key]))
					unset($arr[$key]);
			} 
			elseif ($value == '') 
			{
				unset($arr[$key]);
			}
		}
		if($arr==NULL)
			return false;
		else 
			return true;
	}
	
	public static function byteStrToInt($varString)
    {
        if (!is_numeric($varString)) 
		{
            $type = strtoupper(substr($varString, -1));
            $varString = (integer) substr($varString, 0, -1);

            switch ($type)
			{
                case 'K' :
                    $varString *= 1024;
                    break;

                case 'M' :
                    $varString *= 1024 * 1024;
                    break;

                case 'G' :
                    $varString *= 1024 * 1024 * 1024;
                    break;

                default :
                    break;
            }
        }

        return (integer) $varString;
    }
	
	public static function stringToWordsArray($varString)
	{
	    ///Handle chinese whitespace characters.
        ///Despite we require utf-8 input,the user can always input a
		///GBK whitespace.		
		$varString = str_replace("\xe3\x80\x80",' ',$varString);
		///Strip whitespace from the beginning and end.
		$varString = trim($varString);
		
		///Remove extra white-spaces
		$varString = preg_replace('/\s\s+/', ' ', $varString);
		
		///return an empty array for an empty string.
		if(strlen($varString) < 1)
		{
		   return array();
		}
		
        return explode(' ',$varString);		
	}
	
	
}

?>